package extremebeerbook.server;

import javax.jdo.PersistenceManager;
import extremebeerbook.client.GreetingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
		GreetingService {

	public String greetServer(String input) {
		String serverInfo = getServletContext().getServerInfo();
		String userAgent = getThreadLocalRequest().getHeader("User-Agent");
/**
This is the code to add a grain (or whatever else we do.
Once we have a type set in the datastore, more instances
can be added directly through the Google App Engine.
*/
		PersistenceManager pm = PMF.get().getPersistenceManager();

//        Grain grain = new Grain("Dry Amber Malt", "DME", 12.5f, 1.044f);
        Hop hop = new Hop("Admiral", 1, "United Kingdon", 14.75f, 0.0f, "Boil", 0.0f, "Bittering hops derived from Wye Challenger", "Bittering", "Pellet", 5.6f, 15.0f, "0.00 oz.", "0.00 oz.", 0);
                                  
//        try {
//            pm.makePersistent(grain);
//            pm.makePersistent(hop);
//        } finally {
//            pm.close();
//        }

		return "Hello, " + input + "!<br><br>I am running " + serverInfo
				+ ".<br><br>It looks like you are using:<br>" + userAgent;
	}
}
